package org.hongbo.springbootebsapi.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class ResponseResultUtil {

    public static void print(HttpServletResponse response,int httpStatus, Object message){
        try {
//            response.setStatus(HttpStatus.OK.value());
            response.setStatus(httpStatus);
            response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
            response.setHeader("Cache-Control", "no-cache, must-revalidate");
            PrintWriter writer = response.getWriter();
            writer.write(JSON.toJSONString(message, SerializerFeature.PrettyFormat, SerializerFeature.DisableCircularReferenceDetect));
//            writer.write(String.valueOf(message));
            writer.flush();
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
